package com.yzd.learnjava.concurrency;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ExplicitCricalSection {
	public static void main(String[] args) {
		PairManager pman1 = new ExplicitManager1();
		PairManager pman2 = new Explicitmanager2();
		
		CriticalSection.testApproaches(pman1, pman2);
	}
}

class ExplicitManager1 extends PairManager{
	private Lock lock = new ReentrantLock();
	public synchronized void inCrement() {
		lock.lock();
		try {
			p.inCrementX();
			p.inCrementY();
			store(getPair());
		}finally {
			lock.unlock();
		}
	}
}

class Explicitmanager2 extends PairManager{
	private Lock lock = new ReentrantLock();
	public void inCrement() {
		Pair temp;
		lock.lock();
		try {
			p.inCrementX();
			p.inCrementY();
			temp = getPair();
		} finally {
			lock.unlock();
		}
		store(temp);
	}
}
